package com.atguigu.msmservice.controller;

import com.atguigu.commonutils.R;
import com.atguigu.msmservice.service.MsmApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * @author fxy
 * @date 2022/5/11 11:39
 */
@RestController
@RequestMapping("/edumsm/msm")
//@CrossOrigin
public class MsmApiController {

    @Autowired
    private MsmApiService msmApiService;

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @GetMapping("/send/{phone}")
    public R send(@PathVariable String phone){
//        String code = msmApiService.send(phone);
        String code = "1234";
        if (code==null){
            return R.error().message("发送短信失败！！！");
        }
        redisTemplate.opsForValue().set(phone,code,5, TimeUnit.MINUTES);
        return R.ok();
    }
}
